import api from "@/api/apiServer.js";
const columns = [
  {
    title: "序号",
    dataIndex: "index",
    key: "index",
    customRender: (text, record, index) => `${index + 1}`,
    align: "center",
  },
  {
    title: "产线名称",
    dataIndex: "name",
    key: "name",
    align: "center",
  },
  {
    title: "产线编号",
    dataIndex: "serialNumber",
    key: "serialNumber",
    align: "center",
  },
  {
    title: "产线负责人",
    dataIndex: "principalName",
    key: "principalName",
    align: "center",
  },
  {
    title: "产线位置",
    dataIndex: "location",
    key: "location",
    align: "center",
  },
  {
    title: "机床",
    dataIndex: "equipNums",
    key: "equipNums",
    align: "center",
  },
  {
    title: "操作",
    width: 200,
    dataIndex: "action",
    key: "action",
    align: "center",
    scopedSlots: { customRender: "action" },
  },
];

// 选择负责人
const userColumns = [
  {
    title: "序号",
    width: 80,
    dataIndex: "index",
    key: "index",
    align: "center",
    customRender: (text, record, index) => `${index + 1}`,
  },
  {
    title: "员工姓名",
    dataIndex: "name",
    align: "center",
    key: "name",
  },
  {
    title: "性别",
    align: "center",
    dataIndex: "sex",
    key: "sex",
    customRender: (text, record, index) => {
      return caseSex(text);
    },
  },
  {
    title: "状态",
    align: "center",
    key: "staus",
    dataIndex: "staus",
  },
  {
    title: "员工编号",
    align: "center",
    key: "employeeNumber",
    dataIndex: "employeeNumber",
  },
  {
    title: "部门",
    align: "center",
    key: "department",
    dataIndex: "department",
  },
  {
    title: "职务",
    align: "center",
    key: "position",
    dataIndex: "position",
  },
  {
    title: "移动电话",
    align: "center",
    key: "phone",
    dataIndex: "phone",
  },
  {
    title: "籍贯",
    align: "center",
    key: "nativePlace",
    dataIndex: "nativePlace",
  },
];

function caseSex(value) {
  switch (value) {
    case 0:
      return "女";
    case 1:
      return "男";
  }
}

const equipmentColumns = [
  {
    title: "序号",
    dataIndex: "index",
    key: "index",
    customRender: (text, record, index) => `${index + 1}`,
    align: "center",
  },
  {
    title: "设备编号",
    dataIndex: "equipmentNumber",
    key: "equipmentNumber",
    align: "center",
  },
  {
    title: "设备名称",
    dataIndex: "equipmentName",
    key: "equipmentName",
    align: "center",
  },
  {
    title: "设备型号",
    dataIndex: "equipmentModel",
    key: "equipmentModel",
    align: "center",
  },

  // {
  //   title: "用户部门",
  //   dataIndex: "userDepartment",
  //   key: "userDepartment",
  //   align: "center",
  // },

  // {
  //   title: "管理负责人",
  //   dataIndex: "managementResponsiblePerson",
  //   key: "managementResponsiblePerson",
  //   align: "center",
  // },

  // {
  //   title: "设备类型",
  //   dataIndex: "equipmentTypeName",
  //   key: "equipmentTypeName",
  //   align: "center",
  // },
];
// 选择产线负责人
const userModel = {
  replaceFields: {
    children: "childList",
    title: "departmentName",
    key: "id",
    value: "id",
  },
  treeKey: "DepartmentTree",
  tableKey: "UserList",
  searchKey: "departmentId",
  name: "name",
  filename: "UserModal",
  columns: userColumns,
  tableOption: [],
};

// 选择设备
const equipmentModel = {
  replaceFields: {
    children: "equipmentTypeList",
    title: "equipmentTypeName",
    key: "id",
  },
  treeKey: "equipmentTypeList",
  tableKey: "equipmentListPage",
  searchKey: "equipmentType",
  name: "equipmentName",
  code: "equipmentNumber",
  filename: "EquipMentModal",
  columns: equipmentColumns,
  mode: "checkbox",
  tableOption: [],
};
// 数据查询参数
let params = { pageNumber: 1, pageSize: 99999, deleteFlag: "N" };
// 获取责任人数据源
async function getUser() {
  const res = await api.UserList(params);
  userModel.tableOption = res.data.data;
}
// 获取设备数据源
async function getEquipment() {
  const res = await api.equipmentListPage(params);
  equipmentModel.tableOption = res.data.data;
}
getUser();
getEquipment();

export { columns, userModel, equipmentModel };
